<template xmlns:el-col="http://www.w3.org/1999/html">
  <div class="binding-page password-page">
    <div class="setting-page-right-title">
      <div class="setting-right-name">
        <div class="setting-top-name">修改密码</div>
        <div class="setting-bottom-line"></div>
      </div>
    </div>
    <div class="binding-content">
      <el-form label-width="130px" label-position="right"  style="width: 590px">
        <el-form-item label="当前登录账号：">
          <span class="text-phone">{{account}}</span>
        </el-form-item>
        <el-form-item label="旧密码：">
          <el-input class="theme-input" placeholder="请输入旧密码" v-model="params.oldPass" style="width: 270px">
          </el-input>
        </el-form-item>
        <el-form-item label="新密码：">
          <el-input class="theme-input" show-password placeholder="请输入新密码" v-model="params.newpass"  style="width: 270px">
          </el-input>
        </el-form-item>
        <el-form-item label="确认新密码：">
          <el-row >
               <el-col :span="14"> <el-input show-password class="theme-input" placeholder="请输入新密码" v-model="params.submitPass"  style="width: 270px">
               </el-input></el-col>
            <el-col :span="10">  <div class="msg" v-if="wmsg.length!=0"><img src="@/assets/img/setting/warn.png">{{wmsg}}</div></el-col>
          </el-row>
        </el-form-item>
        <el-form-item>
          <el-button class="submit-button" @click="submit" >确认修改</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      account:"",
      wmsg:"",
      params: {
        oldPass: '',
        newpass: '',
        submitPass: ''
      }
    }
  },
  mounted(){
    if(localStorage.getItem(localSaved.userInfo)!=null){
      this.account =JSON.parse(localStorage.getItem(localSaved.userInfo)).company.phone;
    }
    this.account = _g.toHide(this.account)
  },
  methods: {
    submit() {
      //确认修改密码
      if (!this.check()) {
        return false
      } else {
        _g.apiPost('/company/updatePassword.do', {oldpassword:this.params.oldPass,password:this.params.newpass}).then(res => {
          _g.toMessage({
            status: res.status,
            msg: res.msg
          })
          if(res.status==0){
            setTimeout(() => {
              location.href = '/login'
            }, 2000)
          }
          console.log(res)
        })
      }
    },
    check() {
      if (this.params.oldPass == '' || this.params.newpass == '' || this.params.submitPass == '') {
        //||validate.isPhone(this.params.phone)
        this.wmsg = "输入不能为空";
        return false
      }
      if (this.params.oldPass == this.params.newpass ) {
        this.wmsg = "新旧密码不能相同";
        return false
      }
      if (this.params.newpass != this.params.submitPass ) {
        this.wmsg = "密码输入不一致";
        return false
      }
      return true
    }
  },
  components: {}
}
</script>

<style lang="scss" scoped>
  .password-page .binding-content>el-form{
    border: 2px solid red;
  }
  .password-page .setting-page-right-title{
    background:rgba(251,251,255,1);
  }
  .password-page .binding-content .msg {
    margin-left: 10px;
    color: rgba(255, 90, 90, 1);
    display: flex;
    align-items: center;
  }
  .password-page .binding-content .msg > img {
    width: 12px;
    height: 12px;
    margin-left: 5px;
    margin-right: 4px;
  }
</style>
